{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## numpy概览\n",
    "- NumPy包的核心是 ndarray 对象。它封装了python原生的同数据类型的 n 维数组，为了保证其性能优良，其中有许多操作都是代码在本地进行编译后执行的。\n",
    "- NumPy的主要对象是同构多维数组。它是一个元素表（通常是数字），所有类型都相同，由非负整数元组索引。在NumPy维度中称为 轴 。\n",
    "\n",
    "## ndarray对象（核心）\n",
    "- ndarray.ndim - 数组的轴（维度）的个数。在Python世界中，维度的数量被称为rank。\n",
    "- ndarray.shape - 数组的维度。这是一个整数的元组，表示每个维度中数组的大小。对于有 n 行和 m 列的矩阵，shape 将是 (n,m)。因此，shape 元组的长度就是rank或维度的个数 ndim。\n",
    "- ndarray.size - 数组元素的总数。这等于 shape 的元素的乘积。\n",
    "- ndarray.dtype - 一个描述数组中元素类型的对象。可以使用标准的Python类型创建或指定dtype。另外NumPy提供它自己的类型。例如numpy.int32、numpy.int16和numpy.float64。\n",
    "- ndarray.itemsize - 数组中每个元素的字节大小。例如，元素为 float64 类型的数组的 itemsize 为8（=64/8），而 complex32 类型的数组的 itemsize 为4（=32/8）。它等于 ndarray.dtype.itemsize 。\n",
    "- ndarray.data - 该缓冲区包含数组的实际元素。通常，我们不需要使用此属性，因为我们将使用索引访问数组中的元素。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n",
      "(3, 5)\n",
      "2\n",
      "int32\n",
      "4\n",
      "15\n",
      "<class 'numpy.ndarray'>\n",
      "float64\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.arange(15).reshape(3, 5)\n",
    "print(a)\n",
    "\n",
    "print(a.shape)\n",
    "print(a.ndim)\n",
    "print(a.dtype)\n",
    "print(a.itemsize)\n",
    "print(a.size)\n",
    "print(type(a))\n",
    "\n",
    "#改变dytpe\n",
    "print(a.astype(float).dtype)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 创建数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 3 4]\n",
      "int32\n",
      "float64\n",
      "[[1.5 2.  3. ]\n",
      " [4.  5.  6. ]]\n",
      "[[1.+0.j 2.+0.j]\n",
      " [3.+0.j 4.+0.j]]\n"
     ]
    }
   ],
   "source": [
    "# 通过python数组\n",
    "a = np.array([2,3,4])\n",
    "print(a)\n",
    "print(a.dtype)\n",
    "b = np.array([1.2, 3.5, 5.1])\n",
    "print(b.dtype)\n",
    "\n",
    "# 序列里包含数组\n",
    "b = np.array([(1.5,2,3), (4,5,6)])\n",
    "print(b)\n",
    "\n",
    "# 创建时指定类型\n",
    "c = np.array( [ [1,2], [3,4] ], dtype=complex )\n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0. 0.]\n",
      " [0. 0. 0. 0.]\n",
      " [0. 0. 0. 0.]]\n",
      "[[[1 1 1 1]\n",
      "  [1 1 1 1]\n",
      "  [1 1 1 1]]\n",
      "\n",
      " [[1 1 1 1]\n",
      "  [1 1 1 1]\n",
      "  [1 1 1 1]]]\n",
      "[[1.39069238e-309 1.39069238e-309 1.39069238e-309]\n",
      " [1.39069238e-309 1.39069238e-309 1.39069238e-309]]\n"
     ]
    }
   ],
   "source": [
    "# 初始化创建zero，one；随机创建empty\n",
    "print (np.zeros( (3,4) ))\n",
    "print(np.ones( (2,3,4), dtype=np.int16 ))              \n",
    "print (np.empty( (2,3) ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10 15 20 25]\n",
      "[0.  0.3 0.6 0.9 1.2 1.5 1.8]\n",
      "[0.   0.25 0.5  0.75 1.   1.25 1.5  1.75 2.  ]\n",
      "[ 0.00000000e+00  6.34239197e-02  1.26592454e-01  1.89251244e-01\n",
      "  2.51147987e-01  3.12033446e-01  3.71662456e-01  4.29794912e-01\n",
      "  4.86196736e-01  5.40640817e-01  5.92907929e-01  6.42787610e-01\n",
      "  6.90079011e-01  7.34591709e-01  7.76146464e-01  8.14575952e-01\n",
      "  8.49725430e-01  8.81453363e-01  9.09631995e-01  9.34147860e-01\n",
      "  9.54902241e-01  9.71811568e-01  9.84807753e-01  9.93838464e-01\n",
      "  9.98867339e-01  9.99874128e-01  9.96854776e-01  9.89821442e-01\n",
      "  9.78802446e-01  9.63842159e-01  9.45000819e-01  9.22354294e-01\n",
      "  8.95993774e-01  8.66025404e-01  8.32569855e-01  7.95761841e-01\n",
      "  7.55749574e-01  7.12694171e-01  6.66769001e-01  6.18158986e-01\n",
      "  5.67059864e-01  5.13677392e-01  4.58226522e-01  4.00930535e-01\n",
      "  3.42020143e-01  2.81732557e-01  2.20310533e-01  1.58001396e-01\n",
      "  9.50560433e-02  3.17279335e-02 -3.17279335e-02 -9.50560433e-02\n",
      " -1.58001396e-01 -2.20310533e-01 -2.81732557e-01 -3.42020143e-01\n",
      " -4.00930535e-01 -4.58226522e-01 -5.13677392e-01 -5.67059864e-01\n",
      " -6.18158986e-01 -6.66769001e-01 -7.12694171e-01 -7.55749574e-01\n",
      " -7.95761841e-01 -8.32569855e-01 -8.66025404e-01 -8.95993774e-01\n",
      " -9.22354294e-01 -9.45000819e-01 -9.63842159e-01 -9.78802446e-01\n",
      " -9.89821442e-01 -9.96854776e-01 -9.99874128e-01 -9.98867339e-01\n",
      " -9.93838464e-01 -9.84807753e-01 -9.71811568e-01 -9.54902241e-01\n",
      " -9.34147860e-01 -9.09631995e-01 -8.81453363e-01 -8.49725430e-01\n",
      " -8.14575952e-01 -7.76146464e-01 -7.34591709e-01 -6.90079011e-01\n",
      " -6.42787610e-01 -5.92907929e-01 -5.40640817e-01 -4.86196736e-01\n",
      " -4.29794912e-01 -3.71662456e-01 -3.12033446e-01 -2.51147987e-01\n",
      " -1.89251244e-01 -1.26592454e-01 -6.34239197e-02 -2.44929360e-16]\n"
     ]
    }
   ],
   "source": [
    "# arrange 创建\n",
    "print(np.arange( 10, 30, 5 ))\n",
    "print(np.arange( 0, 2, 0.3 ))\n",
    "\n",
    "#对于小数点，用linspace创建\n",
    "from numpy import pi\n",
    "print(np.linspace( 0, 2, 9 ))\n",
    "\n",
    "x = np.linspace( 0, 2*pi, 100 )\n",
    "f = np.sin(x)\n",
    "print(f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 打印数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5]\n",
      "[[ 0  1  2]\n",
      " [ 3  4  5]\n",
      " [ 6  7  8]\n",
      " [ 9 10 11]]\n",
      "[[[ 0  1  2  3]\n",
      "  [ 4  5  6  7]\n",
      "  [ 8  9 10 11]]\n",
      "\n",
      " [[12 13 14 15]\n",
      "  [16 17 18 19]\n",
      "  [20 21 22 23]]]\n"
     ]
    }
   ],
   "source": [
    "# print和reshape函数\n",
    "a = np.arange(6)       \n",
    "print(a)\n",
    "\n",
    "b = np.arange(12).reshape(4,3)     \n",
    "print(b)\n",
    "\n",
    "c = np.arange(24).reshape(2,3,4)  \n",
    "print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "[['Year' 'WHO region' 'Country' 'Beverage Types' 'Display Value']\n",
      " ['1986' 'Western Pacific' 'Viet Nam' 'Wine' '0']\n",
      " ['1986' 'Americas' 'Uruguay' 'Other' '0.5']\n",
      " ...\n",
      " ['1987' 'Africa' 'Malawi' 'Other' '0.75']\n",
      " ['1989' 'Americas' 'Bahamas' 'Wine' '1.5']\n",
      " ['1985' 'Africa' 'Malawi' 'Spirits' '0.31']]\n"
     ]
    }
   ],
   "source": [
    "#读取数据\n",
    "world_alchohol = np.genfromtxt(\"./../../data/world_alcohol.txt\",delimiter=\",\",dtype=str,encoding=\"utf-8\")\n",
    "print(type(world_alchohol))\n",
    "print(world_alchohol)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数学运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[20 29 38 47]\n",
      "[0 1 4 9]\n",
      "[ 9.12945251 -9.88031624  7.4511316  -2.62374854]\n",
      "[ True  True False False]\n"
     ]
    }
   ],
   "source": [
    "a = np.array( [20,30,40,50] )\n",
    "b = np.arange( 4 )\n",
    "\n",
    "c = a-b\n",
    "print(c)\n",
    "print(b**2)\n",
    "print(10*np.sin(a))\n",
    "print(a<35)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 0]\n",
      " [0 4]]\n",
      "[[5 4]\n",
      " [3 4]]\n",
      "[[5 4]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "# 乘积和矩阵乘积@\n",
    "A = np.array( [[1,1],\n",
    "          [0,1]] )\n",
    "B = np.array( [[2,0],\n",
    "           [3,4]] )\n",
    "print(A * B)   \n",
    "print(A @ B)           \n",
    "print(A.dot(B))    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## axis指定操作某条轴"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = np.arange(12).reshape(3,4)\n",
    "print(b.sum(axis=0)\n",
    "print(b.min(axis=1))\n",
    "print(b.cumsum(axis=1))                         # cumulative sum along each row"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通函数\n",
    "- 另见这些通函数\n",
    "all\n",
    "， any ， apply_along_axis ， argmax ， argmin ， argsort ， average ， bincount ， ceil ， clip ， conj ， corrcoef ， cov ， cross ， cumprod ， cumsum ， diff ， dot ， floor ， inner ， INV ， lexsort ， max ， maximum ， mean ， median ， min ， minimum ， nonzero ， outer ， prod ， re ， round ， sort ， std ， sum ， trace ， transpose ， var ， vdot ， vectorize ， where "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.         2.71828183 7.3890561 ]\n",
      "[0.         1.         1.41421356]\n",
      "[2. 0. 6.]\n"
     ]
    }
   ],
   "source": [
    "B = np.arange(3)\n",
    "print(np.exp(B))\n",
    "print(np.sqrt(B))\n",
    "C = np.array([2., -1., 4.])\n",
    "print(np.add(B, C))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 索引、切片和迭代\n",
    "- 一维的数组可以进行索引、切片和迭代操作的，就像 列表 和其他Python序列类型一样。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15\n",
      "30\n",
      "[ 5 10 15]\n",
      "[10 25 40]\n",
      "[20 25 30]\n",
      "[[ 5 10]\n",
      " [20 25]\n",
      " [35 40]]\n",
      "[[20 25]\n",
      " [35 40]]\n"
     ]
    }
   ],
   "source": [
    "#取某个值\n",
    "vector = np.array([5, 10, 15, 20])\n",
    "matrix = np.array([[5, 10, 15], [20, 25, 30], [35, 40, 45]])\n",
    "number_1 = vector[2]#15\n",
    "number_2 = matrix[1,2]#30\n",
    "print(number_1)\n",
    "print(number_2)\n",
    "#分割取多个值,和列表差不多\n",
    "print(vector[0:3])#[ 5 10 15]\n",
    "#取列或行\n",
    "print(matrix[:,1])#[10 25 40]\n",
    "print(matrix[1])#[20 25 30]\n",
    "#取多行多列\n",
    "print(matrix[:,0:2])#[[ 5 10] [20 25] [35 40]]\n",
    "print(matrix[1:3,0:2])#[[20 25] [35 40]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4]\n",
      "int32\n",
      "[1. 2. 3. 4.]\n",
      "float64\n",
      "['1' '2' '3' '4']\n"
     ]
    }
   ],
   "source": [
    "#判断类型----数组里面的元素必须是同一类型的\n",
    "numbers = np.array([1,2,3,4])\n",
    "print(numbers)#int32\n",
    "#判断类型\n",
    "print(numbers.dtype)\n",
    "#更改类型\n",
    "numbers = np.array([1, 2, 3, 4.0])\n",
    "print(numbers)#[1. 2. 3. 4.]\n",
    "print(numbers.dtype)#float64\n",
    "#改成str类型\n",
    "#改变一个类型其他的都改变\n",
    "numbers = np.array([1, 2, 3, '4'])\n",
    "print(numbers)#['1' '2' '3' '4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[False False False]\n",
      " [False  True False]\n",
      " [False False False]]\n",
      "[False  True False False]\n",
      "[10]\n",
      "[False  True False]\n",
      "[[20 25 30]]\n"
     ]
    }
   ],
   "source": [
    "import numpy\n",
    "#判断矩阵是否含某个值\n",
    "def Judge_bool():\n",
    "    vector = numpy.array([5, 10, 15, 20])\n",
    "    matrix = numpy.array([[5, 10, 15], [20, 25, 30], [35, 40, 45]])\n",
    "    print(matrix==25)\n",
    "    # 用判断当作索引\n",
    "    equal_to_ten = (vector==10)\n",
    "    print(equal_to_ten)\n",
    "    print(vector[equal_to_ten])\n",
    "    #数组判断出值，可以输出一行或者一列\n",
    "    second_column_25 = (matrix[:,1]==25)\n",
    "    print(second_column_25)\n",
    "    print(matrix[second_column_25,:])\n",
    "Judge_bool()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ True  True False False]\n",
      "[False False False False]\n",
      "[50 50 15 20]\n",
      "[False  True False]\n",
      "[[ 5 10 15]\n",
      " [20 10 30]\n",
      " [35 40 45]]\n"
     ]
    }
   ],
   "source": [
    "#判断矩阵是否含某个值，或与操作\n",
    "def Judeg_and_or(vector,matrix):\n",
    "    enual_to_ten_and_five_1 = (vector==10)|(vector==5)\n",
    "    enual_to_ten_and_five_2 = (vector == 10)&(vector == 5)\n",
    "    print(enual_to_ten_and_five_1)\n",
    "    print(enual_to_ten_and_five_2)\n",
    "    #用取出来的索引，改变某些值\n",
    "    vector[enual_to_ten_and_five_1]=50\n",
    "    print(vector)\n",
    "    #对二维\n",
    "    second_column_25 = matrix[:,1]==25\n",
    "    print(second_column_25)\n",
    "    matrix[second_column_25,1] = 10\n",
    "    print(matrix)\n",
    "Judeg_and_or(vector,matrix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<U1\n",
      "float64\n",
      "[1. 2. 3.]\n",
      "1.0\n",
      "6.0\n",
      "[ 30  60 120]\n",
      "[60 60 90]\n"
     ]
    }
   ],
   "source": [
    "#改变类型,求和，求极值\n",
    "def change_type(matrix):\n",
    "    vector = numpy.array([\"1\", \"2\", \"3\"])\n",
    "    print(vector.dtype)\n",
    "    vector=vector.astype(float)\n",
    "    print(vector.dtype)\n",
    "    print(vector)\n",
    "    #计算函数\n",
    "    print(vector.min())\n",
    "    print(vector.sum())#axis=1按行求和\n",
    "    matrix_1=matrix.sum(axis=1)#[ 30  75 120]\n",
    "    matrix_2 = matrix.sum(axis=0)#按列求和[60 75 90]\n",
    "    print(matrix_1)\n",
    "    print(matrix_2)\n",
    "change_type(matrix)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14]\n",
      "[[ 0  1  2  3  4]\n",
      " [ 5  6  7  8  9]\n",
      " [10 11 12 13 14]]\n",
      "(3, 5)\n",
      "2\n",
      "int32\n",
      "15\n",
      "[[0. 0. 0. 0.]\n",
      " [0. 0. 0. 0.]\n",
      " [0. 0. 0. 0.]]\n",
      "[10 15 20 25]\n",
      "[[ 0  1  2]\n",
      " [ 3  4  5]\n",
      " [ 6  7  8]\n",
      " [ 9 10 11]]\n",
      "[[[1 1 1 1]\n",
      "  [1 1 1 1]\n",
      "  [1 1 1 1]]\n",
      "\n",
      " [[1 1 1 1]\n",
      "  [1 1 1 1]\n",
      "  [1 1 1 1]]]\n",
      "[[0.4769049  0.58368499 0.9625059 ]\n",
      " [0.71189724 0.24648024 0.46846439]]\n",
      "[0.         0.06346652 0.12693304 0.19039955 0.25386607 0.31733259\n",
      " 0.38079911 0.44426563 0.50773215 0.57119866 0.63466518 0.6981317\n",
      " 0.76159822 0.82506474 0.88853126 0.95199777 1.01546429 1.07893081\n",
      " 1.14239733 1.20586385 1.26933037 1.33279688 1.3962634  1.45972992\n",
      " 1.52319644 1.58666296 1.65012947 1.71359599 1.77706251 1.84052903\n",
      " 1.90399555 1.96746207 2.03092858 2.0943951  2.15786162 2.22132814\n",
      " 2.28479466 2.34826118 2.41172769 2.47519421 2.53866073 2.60212725\n",
      " 2.66559377 2.72906028 2.7925268  2.85599332 2.91945984 2.98292636\n",
      " 3.04639288 3.10985939 3.17332591 3.23679243 3.30025895 3.36372547\n",
      " 3.42719199 3.4906585  3.55412502 3.61759154 3.68105806 3.74452458\n",
      " 3.8079911  3.87145761 3.93492413 3.99839065 4.06185717 4.12532369\n",
      " 4.1887902  4.25225672 4.31572324 4.37918976 4.44265628 4.5061228\n",
      " 4.56958931 4.63305583 4.69652235 4.75998887 4.82345539 4.88692191\n",
      " 4.95038842 5.01385494 5.07732146 5.14078798 5.2042545  5.26772102\n",
      " 5.33118753 5.39465405 5.45812057 5.52158709 5.58505361 5.64852012\n",
      " 5.71198664 5.77545316 5.83891968 5.9023862  5.96585272 6.02931923\n",
      " 6.09278575 6.15625227 6.21971879 6.28318531]\n"
     ]
    }
   ],
   "source": [
    "#分配行和列,常用函数\n",
    "def column_row():\n",
    "    print(numpy.arange(15))\n",
    "    a = numpy.arange(15).reshape(3, 5)\n",
    "    print(a)\n",
    "    print(a.shape)\n",
    "    print(a.ndim)#维度\n",
    "    print(a.dtype.name)\n",
    "    print(a.size)\n",
    "    print(numpy.zeros((3, 4)))#初始化为0\n",
    "    #arange\n",
    "    print(numpy.arange(10,30,5))\n",
    "    print(numpy.arange(12).reshape(4,3))\n",
    "    #构造单位矩阵\n",
    "    print(numpy.ones((2, 3, 4), dtype = numpy.int32))\n",
    "    print(numpy.random.random((2, 3)))\n",
    "    #引入π值\n",
    "    from numpy import pi\n",
    "    print(numpy.linspace(0, 2 * pi, 100))#0到2pi平均取100个值\n",
    "column_row()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[20 29 38 47]\n",
      "[19 28 37 46]\n",
      "[0 1 4 9]\n",
      "[ True  True False False]\n",
      "----------\n",
      "[[2 0]\n",
      " [0 4]]\n",
      "[[5 4]\n",
      " [3 4]]\n",
      "[[5 4]\n",
      " [3 4]]\n",
      "[1.         2.71828183 7.3890561 ]\n",
      "[0.         1.         1.41421356]\n",
      "[[6. 5. 7. 6.]\n",
      " [6. 8. 5. 8.]\n",
      " [1. 4. 3. 1.]]\n",
      "[6. 5. 7. 6. 6. 8. 5. 8. 1. 4. 3. 1.]\n",
      "[[6. 5.]\n",
      " [7. 6.]\n",
      " [6. 8.]\n",
      " [5. 8.]\n",
      " [1. 4.]\n",
      " [3. 1.]]\n",
      "-----------\n",
      "[[6. 7. 6. 5. 1. 3.]\n",
      " [5. 6. 8. 8. 4. 1.]]\n",
      "[[6. 5. 7. 6.]\n",
      " [6. 8. 5. 8.]\n",
      " [1. 4. 3. 1.]]\n",
      "---------------\n",
      "[[4. 3. 6. 6.]\n",
      " [1. 3. 1. 9.]]\n",
      "[[4. 3.]\n",
      " [1. 3.]\n",
      " [6. 6.]\n",
      " [1. 9.]]\n",
      "-----------------\n",
      "[array([[1., 1., 4., 9.],\n",
      "       [9., 6., 4., 2.]]), array([[4., 0., 0., 9.],\n",
      "       [4., 4., 2., 1.]]), array([[7., 5., 0., 3.],\n",
      "       [1., 3., 1., 9.]])]\n",
      "[array([[1., 1., 4., 9., 4., 0., 0., 9., 7., 5., 0., 3.]]), array([[9., 6., 4., 2., 4., 4., 2., 1., 1., 3., 1., 9.]])]\n"
     ]
    }
   ],
   "source": [
    "#数组之间的数学运算\n",
    "def math_array():\n",
    "    a = numpy.array([20, 30, 40, 50])\n",
    "    b = numpy.arange(4)\n",
    "    c = a-b\n",
    "    print(c)\n",
    "    c=c-1\n",
    "    print(c)\n",
    "    print(b**2)\n",
    "    print(a<35)\n",
    "    print(\"----------\")\n",
    "    A = numpy.array([[1, 1],\n",
    "                      [0,1]])\n",
    "    B = numpy.array([[2, 0],\n",
    "                      [3,4]])\n",
    "    print(A*B)#*乘是对应位置相乘\n",
    "    print(A.dot(B))#矩阵乘法\n",
    "    print(numpy.dot(A, B))\n",
    "\n",
    "    B= numpy.arange(3)\n",
    "    print(numpy.exp(B))#e的幂次方\n",
    "    print(numpy.sqrt(B))#每个数求平方\n",
    "    #floor向下取整\n",
    "    a = numpy.floor(10 * numpy.random.random((3, 4)))\n",
    "    print(a)\n",
    "    #把矩阵拉成成向量\n",
    "    print(a.ravel())\n",
    "    a.shape = (6,2)\n",
    "    print(a)\n",
    "    print(\"-----------\")\n",
    "    print((a.T))#转置矩阵\n",
    "    #指定为-1的意思是自动计算行数\n",
    "    print(a.reshape(3,-1))\n",
    "    print(\"---------------\")\n",
    "    #取整操作\n",
    "    a = numpy.floor(10 * numpy.random.random((2, 2)))\n",
    "    b = numpy.floor(10 * numpy.random.random((2, 2)))\n",
    "    #行之间的拼接\n",
    "    print((numpy.hstack((a, b))))\n",
    "    #列之间的拼接\n",
    "    print((numpy.vstack((a, b))))\n",
    "    print(\"-----------------\")\n",
    "    a = numpy.floor(10 * numpy.random.random((2, 12)))\n",
    "    print((numpy.hsplit(a, 3)))#按照行进行切分\n",
    "    print((numpy.vsplit(a, 2)))#按照列进行切分\n",
    "math_array()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "2504472330032\n",
      "2504472330032\n",
      "-----------\n",
      "False\n",
      "(12,)\n",
      "[   0    1    2    3 1234    5    6    7    8    9   10   11]\n",
      "2504472330032\n",
      "2504466042192\n",
      "-------------\n",
      "[9999    1    2    3 1234    5    6    7    8    9   10   11]\n",
      "[   0    1    2    3 1234    5    6    7    8    9   10   11]\n"
     ]
    }
   ],
   "source": [
    "#矩阵的复制\n",
    "def copy_arrany():\n",
    "    #等号复制，形式相同，id相当\n",
    "    a = numpy.arange(12)\n",
    "    b = a\n",
    "    print( (b is a) )\n",
    "    print((id(a)))\n",
    "    print((id(b)))\n",
    "    print(\"-----------\")\n",
    "    #指向不同，id不同，共用的值是相同的\n",
    "    c = a.view()#浅复制\n",
    "    print((c is a))\n",
    "    c.shape= 2,6\n",
    "    print(a.shape)\n",
    "    c[0,4] = 1234\n",
    "    print(a)\n",
    "    print(id(a))\n",
    "    print(id(c))\n",
    "    print(\"-------------\")\n",
    "    #指向不同，共用值不同\n",
    "    d = a.copy()#之后d和a就没有关系，深复制\n",
    "    d is a\n",
    "    d[0] = 9999\n",
    "    print(d)\n",
    "    print(a)\n",
    "copy_arrany()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.          0.84147098  0.90929743  0.14112001]\n",
      " [-0.7568025  -0.95892427 -0.2794155   0.6569866 ]\n",
      " [ 0.98935825  0.41211849 -0.54402111 -0.99999021]\n",
      " [-0.53657292  0.42016704  0.99060736  0.65028784]\n",
      " [-0.28790332 -0.96139749 -0.75098725  0.14987721]]\n",
      "[2 0 3 1]\n",
      "[0.98935825 0.84147098 0.99060736 0.6569866 ]\n",
      "-------------\n",
      "[[ 0 10 20 30  0 10 20 30  0 10 20 30  0 10 20 30  0 10 20 30]\n",
      " [ 0 10 20 30  0 10 20 30  0 10 20 30  0 10 20 30  0 10 20 30]\n",
      " [ 0 10 20 30  0 10 20 30  0 10 20 30  0 10 20 30  0 10 20 30]]\n",
      "-----------\n",
      "[[3 4 5]\n",
      " [1 1 2]]\n",
      "[2 3 1 0]\n",
      "[1 2 3 4]\n"
     ]
    }
   ],
   "source": [
    "#排序与索引问题\n",
    "def max_suoying():\n",
    "    data = numpy.sin(numpy.arange(20)).reshape(5, 4)\n",
    "    print(data)\n",
    "    ind = data.argmax(axis=0)\n",
    "    print(ind)\n",
    "    #输出每列最大的索引\n",
    "    data_max = data[ind,range(data.shape[1])]\n",
    "    print(data_max)\n",
    "    print(\"-------------\")\n",
    "    a = numpy.arange(0, 40, 10)\n",
    "    #对a进行扩展\n",
    "    b = numpy.tile(a, (3, 5))\n",
    "    print(b)\n",
    "    print(\"-----------\")\n",
    "    #排序\n",
    "    a = numpy.array([[4, 3, 5], [1, 2, 1]])\n",
    "    b = numpy.sort(a, axis=1)\n",
    "    print(b)\n",
    "    a = numpy.array([4, 3, 1, 2])\n",
    "    #按照索引排序\n",
    "    j = numpy.argsort(a)\n",
    "    print(j)\n",
    "    print(a[j])\n",
    "max_suoying()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 扩充内容\n",
    "- NumPy 中定义的最重要的对象是称为 `ndarray` 的 N 维数组类型。 它描述相同类型的元素集合。 可以使用基于零的索引访问集合中的项目。\n",
    "- 创建\n",
    "\n",
    "```python\n",
    "numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)\n",
    "```\n",
    "\n",
    "- 参数\n",
    "\n",
    "<table cellspacing=\"0\" border=\"1\"><thead><tr><td style=\"background-color:#eff3f5;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><strong><span style=\"color:#4f4f4f;\">序号</span></strong></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#eff3f5;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><strong><span style=\"color:#4f4f4f;\">参数及描述</span></strong></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr></thead><tbody><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">1.</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#ffffff;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">object</span></code>&nbsp;<span style=\"color:#4f4f4f;\">任何暴露数组接口方法的对象都会返回一个数组或任何（嵌套）序列。</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">2.</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">dtype</span></code>&nbsp;<span style=\"color:#4f4f4f;\">数组的所需数据类型，可选。</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">3.</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#ffffff;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">copy</span></code>&nbsp;<span style=\"color:#4f4f4f;\">可选，默认为</span><code><span style=\"color:#4f4f4f;\">true</span></code><span style=\"color:#4f4f4f;\">，对象是否被复制。</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">4.</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">order</span></code>&nbsp;<code><span style=\"color:#4f4f4f;\">C</span></code><span style=\"color:#4f4f4f;\">（按行）、</span><code><span style=\"color:#4f4f4f;\">F</span></code><span style=\"color:#4f4f4f;\">（按列）或</span><code><span style=\"color:#4f4f4f;\">A</span></code><span style=\"color:#4f4f4f;\">（任意，默认）。</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">5.</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#ffffff;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">subok</span></code>&nbsp;<span style=\"color:#4f4f4f;\">默认情况下，返回的数组被强制为基类数组。 如果为</span><code><span style=\"color:#4f4f4f;\">true</span></code><span style=\"color:#4f4f4f;\">，则返回子类。</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">6.</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "\t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">ndimin</span></code>&nbsp;<span style=\"color:#4f4f4f;\">指定返回数组的最小维数。</span></p>\n",
    "\t\t\t</td>\n",
    "\t\t</tr></tbody></table>\n",
    "\n",
    "- #### dtype类型\n",
    "\n",
    "- <table cellspacing=\"0\" border=\"1\"><thead><tr><td style=\"background-color:#eff3f5;border-color:#dddddd;\">\n",
    "  \t\t\t<p style=\"margin-left:0cm;\"><strong><span style=\"color:#4f4f4f;\">序号</span></strong></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#eff3f5;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><strong><span style=\"color:#4f4f4f;\">数据类型及描述</span></strong></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr></thead><tbody><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">1.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">bool_</span></code>&nbsp;<span style=\"color:#4f4f4f;\">存储为一个字节的布尔值（真或假）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">2.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">int_</span></code>&nbsp;<span style=\"color:#4f4f4f;\">默认整数，相当于 C 的</span><code><span style=\"color:#4f4f4f;\">long</span></code><span style=\"color:#4f4f4f;\">，通常为</span><code><span style=\"color:#4f4f4f;\">int32</span></code><span style=\"color:#4f4f4f;\">或</span><code><span style=\"color:#4f4f4f;\">int64</span></code></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">3.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">intc</span></code>&nbsp;<span style=\"color:#4f4f4f;\">相当于 C 的</span><code><span style=\"color:#4f4f4f;\">int</span></code><span style=\"color:#4f4f4f;\">，通常为</span><code><span style=\"color:#4f4f4f;\">int32</span></code><span style=\"color:#4f4f4f;\">或</span><code><span style=\"color:#4f4f4f;\">int64</span></code></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">4.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">intp</span></code>&nbsp;<span style=\"color:#4f4f4f;\">用于索引的整数，相当于 C 的</span><code><span style=\"color:#4f4f4f;\">size_t</span></code><span style=\"color:#4f4f4f;\">，通常为</span><code><span style=\"color:#4f4f4f;\">int32</span></code><span style=\"color:#4f4f4f;\">或</span><code><span style=\"color:#4f4f4f;\">int64</span></code></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">5.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">int8</span></code>&nbsp;<span style=\"color:#4f4f4f;\">字节（-128 ~ 127）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">6.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">int16</span></code><span style=\"color:#4f4f4f;\">&nbsp;16 </span><span style=\"color:#4f4f4f;\">位整数（-32768 ~ 32767）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">7.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">int32</span></code><span style=\"color:#4f4f4f;\">&nbsp;32 </span><span style=\"color:#4f4f4f;\">位整数（-2147483648 ~ 2147483647）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">8.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">int64</span></code><span style=\"color:#4f4f4f;\">&nbsp;64 </span><span style=\"color:#4f4f4f;\">位整数（-9223372036854775808 ~ 9223372036854775807）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">9.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">uint8</span></code><span style=\"color:#4f4f4f;\">&nbsp;8 </span><span style=\"color:#4f4f4f;\">位无符号整数（0 ~ 255）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">10.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">uint16</span></code><span style=\"color:#4f4f4f;\">&nbsp;16 </span><span style=\"color:#4f4f4f;\">位无符号整数（0 ~ 65535）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">11.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">uint32</span></code><span style=\"color:#4f4f4f;\">&nbsp;32 </span><span style=\"color:#4f4f4f;\">位无符号整数（0 ~ 4294967295）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">12.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">uint64</span></code><span style=\"color:#4f4f4f;\">&nbsp;64 </span><span style=\"color:#4f4f4f;\">位无符号整数（0 ~ 18446744073709551615）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">13.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">float_</span></code>&nbsp;<code><span style=\"color:#4f4f4f;\">float64</span></code><span style=\"color:#4f4f4f;\">的简写</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">14.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">float16</span></code>&nbsp;<span style=\"color:#4f4f4f;\">半精度浮点：符号位，5 位指数，10 位尾数</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">15.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">float32</span></code>&nbsp;<span style=\"color:#4f4f4f;\">单精度浮点：符号位，8 位指数，23 位尾数</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">16.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">float64</span></code>&nbsp;<span style=\"color:#4f4f4f;\">双精度浮点：符号位，11 位指数，52 位尾数</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">17.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">complex_</span></code>&nbsp;<code><span style=\"color:#4f4f4f;\">complex128</span></code><span style=\"color:#4f4f4f;\">的简写</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#f7f7f7;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">18.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#f7f7f7;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">complex64</span></code>&nbsp;<span style=\"color:#4f4f4f;\">复数，由两个 32 位浮点表示（实部和虚部）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr><tr><td style=\"background-color:#ffffff;border-color:#dddddd;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><span style=\"color:#4f4f4f;\">19.</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t\t<td style=\"background-color:#ffffff;\">\n",
    "        \t\t\t<p style=\"margin-left:0cm;\"><code><span style=\"color:#4f4f4f;\">complex128</span></code>&nbsp;<span style=\"color:#4f4f4f;\">复数，由两个 64 位浮点表示（实部和虚部）</span></p>\n",
    "        \t\t\t</td>\n",
    "        \t\t</tr></tbody></table>\n",
    "\n",
    "> `dtype`可由一下语法构造：\n",
    ">\n",
    "> numpy.dtype(object, align, copy)\n",
    ">\n",
    "> - `Object`：被转换为数据类型的对象。\n",
    "> - `Align`：如果为`true`，则向字段添加间隔，使其类似 C 的结构体。\n",
    "> - `Copy` ? 生成`dtype`对象的新副本，如果为`flase`，结果是内建数据类型对象的引用。\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
